package com.treeman.friend.dao;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.treeman.friend.Invitation;
import com.treeman.user.User;

@Repository
public class FriendInvitationDaoImpl implements FriendInvitationDao {

	private static Logger log = Logger.getLogger(FriendInvitationDaoImpl.class);

	private SessionFactory sessionFactory;

	@Autowired
	public FriendInvitationDaoImpl(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	private Session currentSession() {
		return sessionFactory.getCurrentSession();
	}

	@Override
	public void saveInvitation(User from, User to) {

		log.debug("Persisting invitation object: from - " + from.getUsername()
				+ "   to - " + to.getUsername());

		Invitation invitation = new Invitation(from, to);
		Object a = currentSession().save(invitation);
		int a2 = 0;
	}

}
